let path=require('path');
const HtmlWebpackPlugin=require('html-webpack-plugin');
const { CleanWebpackPlugin } =require('clean-webpack-plugin');
module.exports={
    mode:'development',
    entry:{
        "depes": ["react", "react-dom"], 
        "app": path.resolve(__dirname,'../../src/react/project/todo/index.js'), // 入口文件,
    },
    output:{
        filename: '[name].js',
        path:path.resolve(__dirname,'../../dist/')
    },
    module:{
        rules:[
            {
                test:/\.js$/i,
                use:{
                    loader:'babel-loader?cacheDirectory',// 缓存每次的解析结果 加载更快
                    options:{
                        presets:[
                            '@babel/preset-env','@babel/preset-react'
                        ],
                        plugins: [
                            "react-hot-loader/babel",
                            "@babel/plugin-proposal-class-properties"
                        ]
                    }
                }
            },
            {
                test:/\.(css|less)$/i,
                use:['style-loader','css-loader', 'less-loader']
            },
            {
                test:/\.(jpg|png)$/,
                use:{
                    loader:'url-loader',
                    options:{
                        publicPath:'./',
                        limit:4*1024,
                    }
                }
            }
        ]
    },
    devtool: 'cheap-module-source-map',
    devServer: {
        compress: true, //是否启用gzip压缩
        port: 8900 //提供访问的端口
    },
    plugins:[
        new HtmlWebpackPlugin({
            template:path.resolve(__dirname,'../../project/todo/index.html'),//查找模板文件
        }),
        new CleanWebpackPlugin()   //清空dist目录下的文件
    ],
    resolve: {
        alias: {
          "@react": path.resolve(__dirname, '../../src/react/'),
          "@static": path.resolve(__dirname, '../../static/css/'),
          "@project": path.resolve(__dirname, '../../project'),
          "@libs": path.resolve(__dirname, '../../libs'),
          "@store": path.resolve(__dirname, '../../store')
        }
    }
}
